package com.sinosoft.emplmis.jobless.service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

import com.sinosoft.emplmis.jobless.entity.JoblessInfoEntity;
import com.sinosoft.emplmis.jobless.manager.JoblessInfoManager;
import com.sinosoft.emplmis.jobless.web.dto.JoblessInfoData;
import com.sinosoft.emplmis.jobless.web.dto.JoblessSearchData;
import com.sinosoft.framework.core.api.domain.UserOrgData;
import com.sinosoft.framework.core.common.exception.BusinessException;

public class JoblessInfoService {

	/**
	 * 失业人员服务类
	 */
	
	private JoblessInfoManager joblessInfoManager;

	public JoblessInfoManager getJoblessInfoManager() {
		return joblessInfoManager;
	}

	public void setJoblessInfoManager(JoblessInfoManager joblessInfoManager) {
		this.joblessInfoManager = joblessInfoManager;
	}
	
	/**
	  * 获取失业人员信息
	  * @param data
	  * @return
	  */
	public List<JoblessInfoEntity> joblessInfoList(JoblessSearchData data) {
		Logger.getRootLogger().info("获取失业人员信息");
		return joblessInfoManager.selectAll(data);
	}
	
	/**
	  * 根据主键删除一条失业人员信息
	  * @param unemployedId
	  * @return
	  */
	public int deleteByPrimaryKey(String unemployedId) {
		Logger.getRootLogger().info("根据主键删除失业人员信息");
	    return joblessInfoManager.deleteByPrimaryKey(unemployedId);
    }
	
	/**
	  * 根据主键提交放弃求职人员的申请
	  * @param unemployedId
	  * @return
	  */
	public int auditSubmitInfo(String unemployedId) {
		Logger.getRootLogger().info("根据主键提交放弃求职人员的申请");
	    return joblessInfoManager.auditSubmitInfo(unemployedId);
    }
	
	/**
	  * 根据主键审核放弃求职人员的申请
	  * @param unemployedId
	  * @return
	  */
	public int auditGiveupInfo(String unemployedId) {
		Logger.getRootLogger().info("根据主键审核放弃求职人员的申请");
	    return joblessInfoManager.auditGiveupInfo(unemployedId);
    }
	
	/**
	  * 根据主键删除放弃求职人员的申请
	  * @param unemployedId
	  * @return
	  */
	public int giveupDel(String unemployedId) {
		Logger.getRootLogger().info("根据主键删除放弃求职人员的申请");
	    return joblessInfoManager.giveupRemove(unemployedId);
    }
	 
	/**
	  * 根据主键获取一条失业人员信息
	  * @param 
	  * @return
	  */
    public JoblessInfoEntity selectByPrimaryKey(String unemployedId){
    	Logger.getRootLogger().info("根据主键获得失业人员信息");
		return joblessInfoManager.selectByPrimaryKey(unemployedId);
	}
	
	/**
	 * 添加失业人员信息
	 * @return
	 */
	public int saveJoblessInfo(JoblessInfoData record) {
		Logger.getRootLogger().info("添加失业人员信息");
		JoblessInfoEntity joblessInfoEntity = new JoblessInfoEntity();
		//生成唯一主键
		record.setUnemployedId(UUID.randomUUID().toString().trim().replaceAll("-", ""));
//		record.setInputdate(new Date());
//		record.setModifydate(new Date());
		 
		/*Session session = SecurityUtils.getSubject().getSession();
		//用户机构信息
		UserOrgData userOrgData = (UserOrgData) session.getAttribute("userOrg");
		if(userOrgData==null){
		    throw new BusinessException("当前用户没有设定社区");
		}*/
		 
//		laborInfoEntity.setStreet(record.getStreet());
//		laborInfoEntity.setCommunity(record.getCommunity());

		//将dto转换为实体类
		joblessInfoEntity.toEntityData(joblessInfoEntity,record,"");
		return joblessInfoManager.insert(joblessInfoEntity);
    }
	
	/**
	  * 根据主键修改失业人员信息
	  * @param record
	  * @return
	  */
	 public int updateByPrimaryKey(JoblessInfoEntity record) {
		 Logger.getRootLogger().info("根据主键修改失业人员信息");
		 return joblessInfoManager.updateByPrimaryKey(record);
	 }
	 
	 /**
	  * 根据主键修改放弃求职人员信息
	  * @param record
	  * @return
	  */
	public int updateJoblessGiveup(JoblessInfoEntity record) {
		Logger.getRootLogger().info("根据主键修改放弃求职人员信息");
		return joblessInfoManager.updateJoblessGiveup(record);
	}
	
	/**
	  * 根据主键修改放弃求职人员信息
	  * @param record
	  * @return
	  */
	public int updateDifficulty(JoblessInfoEntity record) {
		Logger.getRootLogger().info("根据主键修改困难人员信息");
		return joblessInfoManager.updateDifficulty(record);
	}
	
	public List<JoblessInfoEntity> difficultyInfoList(JoblessSearchData data) {
		Logger.getRootLogger().info("获取困难人员信息");
		return joblessInfoManager.difficultyInfoList(data);
	}
	
	public List<JoblessInfoEntity> historyDifficultyInfoList(JoblessSearchData data) {
		Logger.getRootLogger().info("获取历史困难人员信息");
		return joblessInfoManager.historyDifficultyInfoList(data);
	}
	
	public List<JoblessInfoEntity> joblessRealizeList(JoblessSearchData data) {
		Logger.getRootLogger().info("获取当年实现就业人员信息");
		return joblessInfoManager.joblessRealizeList(data);
	}
	
	public List<JoblessInfoEntity> joblessReduceList(JoblessSearchData data) {
		Logger.getRootLogger().info("获取失业人员客观原因减少信息");
		return joblessInfoManager.joblessReduceList(data);
	}
	
	public List<JoblessInfoEntity> joblessGiveupList(JoblessSearchData data) {
		Logger.getRootLogger().info("获取放弃求职人员减少申报信息");
		return joblessInfoManager.joblessGiveupList(data);
	}
	
	/**
	  * 获取总条目数
	  * @param data
	  * @return
	  */
	 public int count(JoblessSearchData data){
		 Logger.getRootLogger().info("获取总条目数");
	     return joblessInfoManager.count(data);
    }
	 
	 /**
	  * 获取总条目数
	  * @param data
	  * @return
	  */
    public int countDifficulty(JoblessSearchData data){
    	Logger.getRootLogger().info("获取总条目数");
	    return joblessInfoManager.countDifficulty(data);
    }
    
    public int countHistoryDifficulty(JoblessSearchData data){
    	Logger.getRootLogger().info("获取总条目数");
	    return joblessInfoManager.countHistoryDifficulty(data);
    }
	 
	 /**
	  * 获取总条目数
	  * @param data
	  * @return
	  */
	 public int countrealjob(JoblessSearchData data){
		 Logger.getRootLogger().info("获取总条目数");
	     return joblessInfoManager.countrealjob(data);
    }
	 
	 public int countremovereason(JoblessSearchData data) {
			Logger.getRootLogger().info("获取总条目数");
			return joblessInfoManager.countremovereason(data);
		}
	 public int countgiveup(JoblessSearchData data) {
			Logger.getRootLogger().info("获取总条目数");
			return joblessInfoManager.countgiveup(data);
		}
}
